/*package com.ym.b2b.order;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ym.b2b.cache.configcache.WebAppConfig;
import com.ym.b2b.commons.exception.BaseException;
import com.ym.b2b.haipai.db.DBFactroy;
import com.ym.b2b.haipai.vo.XCOrderParam;
import com.ym.b2b.order.dao.EmSOrderConfirmItemDao;
import com.ym.b2b.order.sqlbean.EmSOrderConfirmItem;
import com.ym.b2b.order.tk.TKDBFactroy;
import com.ym.b2b.order.tk.XcService;
import com.ym.b2b.order.vo.OrderInfoVO;
import com.zc.commons.base.Result;
import com.zc.commons.service.ZcService;

@Service("defaultTradeRequest")
public class CopyOfDefaultTradeRequestImpl extends ZcService implements TradeRequest {

    @Autowired
    private EmSOrderConfirmItemDao emSOrderItemDao;

    @Autowired
    private XcService              xcService;

    private Connection             conn;

    public Result bookingErpOrder(OrderInfoVO vo, List<EmSOrderConfirmItem> list) throws BaseException {
        logger.info(" ------ERP 下单节点");
        Result ret = new Result();
        String nowCase = WebAppConfig.getConfigMap().get("CURRENT_USE") == null ? "" : WebAppConfig.getConfigMap().get("CURRENT_USE").toString();
        if (!"".equals(nowCase)) {
            logger.info(" ------当前对接系统：" + nowCase + " (XC=宣城医药在线  HAIPAI=海派医药在线)");
            if (nowCase.equals("XC")) { // 宣城医药在线
                if (isDo()) { // 在application_config.xml中控制判断是否对接ERP下单
                    logger.info(" ------宣城医药在线下单开始");
                    ret = xcService.dealOrder(vo);

                    if (ret.getCode().equals(Result.CODE_100)) {
                        return ret;
                    }
                }
            }
        }
        return ret;
    }

    private boolean isDo() {
        if (null != WebAppConfig.getConfigMapServiceRouter().get("DO_ERP_ORDER") && "true".equals(WebAppConfig.getConfigMapServiceRouter().get("DO_ERP_ORDER"))) {
            return true;
        } else {
            return false;
        }
    }

    *//*** 下单接口 处理海派 本地系统部分 本地系统 部分 ***//*
    private Result dealOrder(OrderInfoVO vo, String productCodes) {
        Result ret = new Result();
        XCOrderParam XCOrderParam = new XCOrderParam();
        Connection conn = null;
        try {
            conn = DBFactroy.getHaiPaiCon();
        } catch (Exception e) {
            throw new BaseException(e.getMessage());
        }
        ResultSet rs = null;
        try {
            *//** NO.1************* 告知本地系统 下单 ************//*
            logger.debug("-----下单报文：webdjpro('" + XCOrderParam.CUSTOMER_ORDER + "','" + vo.getUser().getBuyerCode()
                         + "','" + vo.getOrderCode() + "','" + productCodes + "',：x,:y,:z)");

            CallableStatement query = conn.prepareCall("{call webdjpro(?,?,?,?,?,?,?)}");
            query.setString(1, XCOrderParam.CUSTOMER_ORDER);
            query.setString(2, vo.getUser().getBuyerCode());
            query.setString(3, vo.getOrderCode());
            query.setString(4, productCodes);
            query.registerOutParameter(5, java.sql.Types.VARCHAR);
            query.registerOutParameter(6, java.sql.Types.VARCHAR);
            query.registerOutParameter(7, java.sql.Types.VARCHAR);
            query.execute();

            XCOrderParam.setCurSqlRet(query.getString(5));
            XCOrderParam.setCurSqlErrMsg(query.getString(6));
            XCOrderParam.setErpCode(query.getString(7));
            ret.putData("orderRet", XCOrderParam);
            if (XCOrderParam.getCurSqlRet().equals("1")) {
                EmSOrderConfirmItem emSOrderConfirmItem = new EmSOrderConfirmItem();
                emSOrderConfirmItem.setOrderCode(vo.getOrderCode());
                emSOrderConfirmItem.setOrderCodeErp(XCOrderParam.getErpCode());
                // emSOrderItemDao.updateEmSOrderConfirmItem(emSOrderConfirmItem);
            } else {
                ret.setCodeResult("100", XCOrderParam.getCurSqlErrMsg());
                return ret;
            }

            *//** NO.2************* 跟新 产品 批号 和有效期 ************//*
            PreparedStatement pstmt = conn.prepareStatement("{call webdjzt(?,?,?)}");
            pstmt.setString(1, XCOrderParam.CUSTOMER_ORDER);//
            pstmt.setString(2, vo.getUser().getBuyerCode());
            pstmt.setString(3, vo.getOrderCode());
            rs = pstmt.executeQuery();
            while (rs.next()) {
                logger.debug("-----更新商品明细：" + rs.getString("spbh") + "|" + rs.getString("sxrq") + "|"
                             + rs.getString("pihao"));

                EmSOrderConfirmItem emSOrderConfirmItem = new EmSOrderConfirmItem();
                emSOrderConfirmItem.setProductCode(rs.getString("spbh"));
                emSOrderConfirmItem.setOrderCode(vo.getOrderCode());
                Integer isExit = emSOrderItemDao.searchEmSOrderConfirmItemBatchNum(emSOrderConfirmItem);

                String dateStr = "0000-00-00";
                if (rs.getString("sxrq") != null && !rs.getString("sxrq").replaceAll(" ", "").equals("")) {
                    dateStr = rs.getString("sxrq");
                }
                if (isExit > 0) {
                    // 修改批次
                    emSOrderConfirmItem.setValidateStr(dateStr);
                    emSOrderConfirmItem.setBatchNumber(rs.getString("pihao"));
                    emSOrderConfirmItem.setConfirmAmount(Double.parseDouble(rs.getString("shl")));
                    emSOrderConfirmItem.setConfirmMoney(Double.parseDouble(rs.getString("hsje")));
                    emSOrderConfirmItem.setOrderCodeErp(XCOrderParam.getErpCode());

                    emSOrderItemDao.updateEmSOrderConfirmItem(emSOrderConfirmItem);
                } else {
                    // 新增批次
                    logger.info("---------------收货订单明细-多批次新增");
                    emSOrderConfirmItem = emSOrderItemDao.searchEmSOrderConfirmItem(emSOrderConfirmItem).get(0);

                    emSOrderConfirmItem.setValidateStr(dateStr);
                    emSOrderConfirmItem.setBatchNumber(rs.getString("pihao"));
                    emSOrderConfirmItem.setConfirmAmount(Double.parseDouble(rs.getString("shl")));
                    emSOrderConfirmItem.setConfirmMoney(Double.parseDouble(rs.getString("hsje")));
                    emSOrderConfirmItem.setOrderCodeErp(XCOrderParam.getErpCode());
                    emSOrderConfirmItem.setOrderConfirmItemId(null);
                    emSOrderItemDao.saveOrUpdateEmSOrderConfrimItem(emSOrderConfirmItem);
                }
            }
            if (rs != null) {
                rs.close();
            }
            if (conn != null) {
                conn.close();
            }
            return ret;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new BaseException("通知本地系统失败或修改销售单明细失败：" + e.getMessage());
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
                throw new BaseException("关闭本地数据库连接异常:" + e.getMessage());
            }

        }
    }

    *//**
     * 没做
     *//*
    @Override
    public Result payErpOrder() throws BaseException {
        // TODO Auto-generated method stub
        return null;
    }

    *//**
     * 没做
     *//*
    @Override
    public Result completeErpOrder() throws BaseException {
        // TODO Auto-generated method stub
        return null;
    }

    *//**
     * 没做退货接口
     *//*
    @Override
    public Result saleReturnErpOrder() throws BaseException {
        // TODO Auto-generated method stub
        return null;
    }

    *//**
     * 更新订单状态,必须
     *//*
    @Override
    public void updateOrder(OrderInfoVO vo, EmSOrderConfirmItem item) throws BaseException {
        String nowCase = WebAppConfig.getConfigMap().get("CURRENT_USE") == null ? "" : WebAppConfig.getConfigMap().get("CURRENT_USE").toString();
        if (!"".equals(nowCase)) {
            logger.info(" ------当前对接系统：" + nowCase + " (TX=宣城医药在线  HAIPAI=海派医药在线)");
            if (nowCase.equals("XC")) { // 宣城医药在线
                if (isDo()) {
                    logger.info(" ------宣城医药在线下单开始");
                    xcService.updateOrder(vo,item);
                }
            }
        }

    }

    *//**
     * 取消订单接口,必须
     *//*
    @Override
    public Result cancelOrder(OrderInfoVO vo) throws BaseException, SQLException {
        Result ret = new Result();
        if (isDo()) {
            Connection conn = null;
            Statement stmt = null;
            ResultSet rs = null;
            try {
                conn = TKDBFactroy.getTkCon();
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                // 检查宣城ERP 系统订单 是否已被提取
                rs = stmt.executeQuery("SELECT  djbh, rq,xgdjbh,dwbh,hsje,je,she,lxr,dianh,idcard,cangkdzh,ywy,zt,message,lastmodifytime,is_zx  FROM webddhz where djbh='"
                                       + vo.getOrderCode() + "'");

                if (rs.next()) {
                    String isFetch = rs.getString("is_zx");
                    if ("是".equals(isFetch)) {
                        // 已提取 不可取消
                        ret.setCodeResult(Result.CODE_100, "ERP订单已经开票, 不可取消.可联系客服.");
                        return ret;
                    }
                }
                // 取消erp订单 直接删除
                stmt.execute("delete webddmx where djbh='" + vo.getOrderCode() + "'");
                stmt.execute("delete webddhz where djbh='" + vo.getOrderCode() + "'");
                conn.setAutoCommit(true);
                conn.commit();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
                conn.rollback();
                throw new BaseException("ERP异常：" + e.getMessage());
            } finally {
                if (rs != null) rs.close();
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
            return ret;
        } else {
            return ret;
        }
    }

    private Connection getConnInstance() {
        if (null == conn) {
            conn = TKDBFactroy.getTkCon();
        } else {
            // 验证有效性
            try {
                if (!conn.isClosed()) {

                }
                // conn.createStatement().executeQuery("select 1");
            } catch (Exception e) {
                conn = TKDBFactroy.getTkCon();
            }
        }
        return conn;
    }

}
*/